﻿
using Autofac;
using Common.Framework.Core.AutoFac;
using Common.Framework.Core.FluentValidation;
using Common.Framework.Core.Foundation;
using Common.Framework.Core.Minio;
using Common.Framework.Core.Swagger;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using VehicleModule.Api.Repository;
using VehicleModule.Api.Service;

namespace VehicleModule.Api
{
    /// <summary>
    /// 
    /// </summary>
    public class Startup
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="configuration"></param>
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        /// <summary>
        /// 
        /// </summary>
        public IConfiguration Configuration { get; }
        /// <summary>
        /// ApiVersionProvider
        /// </summary>
        private IApiVersionDescriptionProvider provider;

        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
          
            provider = services.AddConfigureSwagger();

            services.CustomConfigureServices(Configuration);
            services.AddScoped<IFueltypeService, FueltypeService>();
            services.AddScoped<ILogService, LogService>();
            services.AddScoped<IRealtimedataService, RealtimedataService>();
            services.AddScoped<IUsersService, UsersService>();
            services.AddScoped<IVehiclesService, VehiclesService>();
            services.AddScoped<IVehicleteamService, VehicleteamService>();

            services.AddScoped<IFueltypeRepository, FueltypeRepository>();
            services.AddScoped<ILogRepository, LogRepository>();
            services.AddScoped<IRealtimedataRepository, RealtimedataRepository>();
            services.AddScoped<IUsersRepository, UsersRepository>();
            services.AddScoped<IVehiclesRepository, VehiclesRepository>();
            services.AddScoped<IVehicleteamRepository, VehicleteamRepository>();

            services.AddControllers().AddCustomControllers();
        }

        /// <summary>
        /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
            app.CustomConfigure(env, provider);
       
        } 

        /// <summary>
        /// Autofac
        /// </summary>
        /// <param name="builder"></param>
        public void ConfigureContainer(ContainerBuilder builder) => builder.RegisterModule<AutofacLoadConfiguration>();
    }
}
